package routers

import (
	"github.com/gin-contrib/cors"
	"github.com/gin-gonic/gin"
	"mini-gde/apis"
	"mini-gde/pkg"
)

func InitRouter() *gin.Engine {
	r := gin.New()
	r.Use(gin.Logger())
	//r.Use(gin.Recovery())
	r.Use(cors.Default())
	gin.SetMode(pkg.RunMode)

	//r.GET("/ping", func(c *gin.Context) {
	//	c.JSON(200, gin.H{
	//		"message": "pong",
	//	})
	//})

	dockerApis := r.Group("/docker/")
	{
		//获取容器列表
		dockerApis.GET("/containers", apis.GetContainers)

		//启动容器
		dockerApis.PUT("/container/start/:id", apis.StartContainer)

		//启动容器
		dockerApis.PUT("/container/stop/:id", apis.StopContainer)

		//获取镜像列表
		dockerApis.GET("/images", apis.GetImages)

		dockerApis.POST("/build", apis.BuildDockerfile)
	}

	k8sApis := r.Group("/k8s")
	{
		//test 获取pod列表
		k8sApis.GET("/pods", apis.ListPods)
	}

	gitApis := r.Group("/git")
	{
		gitApis.POST("/clone", apis.CloneRepo)
	}

	helmApis := r.Group("/helm")
	{
		helmApis.POST("/install", apis.HelmInstall)
	}

	return r
}
